package org.boot.ssm.wxshop.web.controller;

import org.boot.ssm.wxshop.domain.CarouselImg;
import org.boot.ssm.wxshop.domain.GoodsTypeSmall;
import org.boot.ssm.wxshop.service.CarouselService;
import org.boot.ssm.wxshop.service.GoodsTypeSmallService;
import org.boot.ssm.wxshop.web.common.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: wxshop
 * @description: 轮播图控制器
 * @author: Mr.Wang
 * @create: 2018-03-17 13:50
 **/
@Controller
@RequestMapping(value = "/carousel")
public class CarouselController {
    @Autowired
    private CarouselService carouselService;
    @Autowired
    private GoodsTypeSmallService goodsTypeSmallService;

    @RequestMapping(value = "/goCarouselPage")
    /*****************************
     * @Description: 去到显示轮播图列表页面
     * @Param: []
     * @return: java.lang.String
     * @Author: 刘涛
     * @Date: 2018/3/17
     *******************************/
    public String goCarouselPage(Model model) {
        model.addAttribute("list", carouselService.selectAllAndGoods());
        return "backstage/carousel/carousel";
    }


    @RequestMapping(value = "/goAddPage")
    /*****************************
     * @Description: 去添加页面
     * @Param: []
     * @return: java.lang.String
     * @Author: 刘涛
     * @Date: 2018/3/17
     *******************************/
    public String goAddPage() {
        return "backstage/carousel/addorupdate";
    }

    @RequestMapping(value = "/goUpdatePage/{id}")
    /*****************************
     * @Description: 去修改页面
     * @Param: [id]
     * @return: java.lang.String
     * @Author: 刘涛
     * @Date: 2018/3/17
     *******************************/
    public String goUpdatePage(@PathVariable("id") Integer id, Model model) {
        model.addAttribute("carousel", carouselService.selectAllAndGoodsById(id));
        return "backstage/carousel/addorupdate";
    }

    @RequestMapping(value = "/selcetGoods")
    /*****************************
     * @Description: 选择商品
     * @Param: []
     * @return: java.lang.String
     * @Author: 刘涛
     * @Date: 2018/3/17 
     *******************************/
    public String selcetGoods(Model model) {
        GoodsTypeSmall goodsTypeSmall = new GoodsTypeSmall();
        goodsTypeSmall.setIsDelete(1);
        //获取所有商品子类型
        model.addAttribute("typeList", goodsTypeSmallService.queryParamList(goodsTypeSmall));
        return "backstage/carousel/goodselect";
    }

    @RequestMapping(value = "/addOrUpdate")
    @ResponseBody
    /*****************************
     * @Description: 添加或修改
     * @Param: [carouselImg]
     * @return: org.boot.ssm.wxshop.web.common.JsonResult
     * @Author: 刘涛
     * @Date: 2018/3/17
     *******************************/
    public JsonResult addOrUpdate(CarouselImg carouselImg) {
        return carouselService.addOrUpdate(carouselImg);
    }

    @RequestMapping(value = "/countCarousel")
    @ResponseBody
    /*****************************
     * @Description: 获取轮播图条数
     * @Param: []
     * @return: org.boot.ssm.wxshop.web.common.JsonResult
     * @Author: 刘涛
     * @Date: 2018/3/17
     *******************************/
    public JsonResult countCarousel() {
        return carouselService.countCarousel();
    }

    @RequestMapping("/delete")
    @ResponseBody
    /*****************************
     * @Description: 逻辑删除
     * @Param: [carouselImg]
     * @return: org.boot.ssm.wxshop.web.common.JsonResult
     * @Author: 刘涛
     * @Date: 2018/3/17
     *******************************/
    public JsonResult delete(CarouselImg carouselImg) {
        return carouselService.deleteCarousel(carouselImg);
    }

    @RequestMapping(value = "/frontstage/listCarousel")
    @ResponseBody
    /*****************************
    * @Description: 前台显示轮播图
    * @Param: [] 
    * @return: org.boot.ssm.wxshop.web.common.JsonResult 
    * @Author: 刘涛 
    * @Date: 2018/3/19 
    *******************************/
    public JsonResult frontListCarousel() {
        return new JsonResult(200,"加载成功",carouselService.selectAllAndGoods());
    }




}
